﻿
namespace Jayden.Dll.Sc2.Descriptions
{
	public class DelayedActionDescription : ActionDescription
	{
		public delegate void ExecuteDelegate(GameState state);

		private ActionDescription m_Source;
		private long m_Time;
		protected ExecuteDelegate m_Execute;

		public DelayedActionDescription(EntityDescription entity, long time, ExecuteDelegate execute, string id)
			: base(entity, id)
		{
			m_Source = null;
			m_Time = time;
			m_Execute = execute;
		}
		public DelayedActionDescription(ActionDescription source, long time, ExecuteDelegate execute, string id = null)
			: base(source.Entity, id ?? source.Id + "Finished")
		{
			m_Source = source;
			m_Time = time;
			m_Execute = execute;
		}

		public ActionDescription Source { get { return m_Source; } }
		public long Time { get { return m_Time; } }

		public override bool IsExecutable(GameState state) { return state.Time >= m_Time; }
		public override void Execute(GameState state) { m_Execute(state); }
	}
}
